package io.renren.modules.dangan.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.dangan.entity.DaJnmlbEntity;
import io.renren.modules.dangan.service.DaJnmlbService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;


/**
 * ${comments}
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-08-03 22:04:01
 */
@RestController
@RequestMapping("/dajnmlb")
@CrossOrigin
public class DaJnmlbController {
    @Autowired
    private DaJnmlbService daJnmlbService;

    /**
     * 列表
     */
    @RequestMapping(value = "/list",method = {POST,GET})
//    @RequiresPermissions("dangan:dajnmlb:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = daJnmlbService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{jnmlbh}")
    @RequiresPermissions("dangan:dajnmlb:info")
    public R info(@PathVariable("jnmlbh") Integer jnmlbh){
        DaJnmlbEntity daJnmlb = daJnmlbService.getById(jnmlbh);

        return R.ok().put("daJnmlb", daJnmlb);
    }
    /**
     * 更新卷内目录的文件
     */
    @RequestMapping("/updateJnmlFile")
//    @RequiresPermissions("dangan:dajnmlb:saveJnmlFile")
    public R updateJnmlFile(@RequestParam Map<String, Object> params){
        return R.ok().put("updateFile",daJnmlbService.updateJnmlFile(params));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("dangan:dajnmlb:save")
    public R save(DaJnmlbEntity daJnmlb){
        daJnmlbService.save(daJnmlb);
        return R.ok().put("data",daJnmlb);
    }
    /**
     * 保存
     */
    @RequestMapping("/saveJnmlFile")
//    @RequiresPermissions("dangan:dajnmlb:save")
    public R saveJnmlFile(DaJnmlbEntity daJnmlb,String uploadJnmlFilePath){
        boolean result=daJnmlbService.saveJnmlFile(daJnmlb,uploadJnmlFilePath);

        return result?R.ok():R.error("上传失败");
    }
    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("dangan:dajnmlb:update")
    public R update(DaJnmlbEntity daJnmlb){
        ValidatorUtils.validateEntity(daJnmlb);
        daJnmlbService.updateById(daJnmlb);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("dangan:dajnmlb:delete")
    public R delete(String jnmlbh){
        daJnmlbService.removeById(jnmlbh);
        return R.ok();
    }

}
